package com.chushouya.controller.manager.admin;

import com.chushouya.common.constant.ServiceType;
import com.chushouya.manager.dto.admin.article.*;
import com.chushouya.manager.service.admin.ArticleCategoryService;
import com.general.framework.core.schema.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "文章分类管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/articleCategory")
public class ArticleCategoryController {

    @Resource
    private ArticleCategoryService articleCatService;

    @GetMapping("/list")
    @ApiOperation("文章分类列表")
    public Response<List<ArticleCatListDTO>> list(ArticleCategoryQuery query) {
        return Response.success(articleCatService.list(query));
    }

    @GetMapping("/detail")
    @ApiOperation("文章分类详情")
    public Response<ArticleCatDetailDTO> detail(Long categoryId) {
        return Response.success(articleCatService.detail(categoryId));
    }

    @PostMapping("/add")
    @ApiOperation("新增文章分类")
    public Response<Void> save(@RequestBody @Valid ArticleCatSaveDTO dto) {
        articleCatService.save(dto);
        return Response.success();
    }

    @PostMapping("/edit")
    @ApiOperation("编辑文章分类")
    public Response<Void> update(@RequestBody @Valid ArticleCatUpdateDTO dto) {
        articleCatService.update(dto);
        return Response.success();
    }

    @PostMapping("/remove")
    @ApiOperation("删除文章分类")
    public Response<Void> remove(Long categoryId) {
        articleCatService.remove(categoryId);
        return Response.success();
    }

    @PostMapping("/switchStatus")
    @ApiOperation("切换文章分类状态")
    public Response<Void> switchStatus(Long id, Integer status) {
        articleCatService.switchStatus(id, status);
        return Response.success();
    }
}
